#include<bits/stdc++.h>
#define gc getchar
#define itn int
#define x first
#define y second
#define eb emplace_back
#define em emplace
#define pb push_back
#define db double
#define y1 yy1_yyds
using namespace std; typedef long long ll; typedef unsigned long long ull;
// https://www.luogu.com.cn/discuss/522581 About "const"
ll read() {
	ll x = 0; short fh = 1; char ch = gc();
	while (!isdigit(ch)) {
		if (ch == '-') fh = -1;
		if (ch < 10) exit(0); 
		ch = gc();
	}
	while (isdigit(ch))
		x = x * 10 + (ch ^ 48), ch = gc();
	return fh * x;
}
#ifndef ONLINE_JUDGE
void debug() {cerr << "\n";}
template<typename Typ1> void debug(Typ1 arg) {cerr << arg << "\n";}
template<typename Typ1, typename ...Typ2> void debug(Typ1 arg, Typ2 ...args) {
	cerr << arg << " ", debug(args...);
}
#else
void debug() {}
template<typename Typ1> void debug(Typ1 arg) {}
template<typename Typ1, typename ...Typ2> void debug(Typ1 arg, Typ2 ...args) {}
#endif
void writeln(ll arg) {printf("%lld\n", arg);}
template<typename ...Typ2> void writeln(ll arg, Typ2 ...args) {
	printf("%lld ", arg), writeln(args...);
}
typedef pair <int, int> pii; typedef pair <ll, ll> pll;
const char Y_E_S[] = "YES", N__O[] = "NO";
// const char Y_E_S[] = "Yes", N__O[] = "No";
// #define infinite_testcase
// #define multiple_testcase
// #define output_Yes_No
const int DUST = 327, N = 314, M = -1;
char s[N][N];
bool vis[N][N];
int x1, y1, x2, y2;
const int dx[] = {1, 0, -1, 0},
		  dy[] = {0, 1, 0, -1};
void dfs(int i, int j) {
	for(int l = 0; l < 4; l++) {
		int x = i + dx[l], y = j + dy[l];
		if(x >= x1 && x <= x2 && y >= y1 && y <= y2 && s[x][y] == '1' && !vis[x][y])
			vis[x][y] = 1, dfs(x, y);
	}
}
bool major(int Case = 1) {
	int n = read(), m = read(), q = read();
	for(int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
	while(q--) {
		x1 = read(), y1 = read(), x2 = read(), y2 = read();
		for(int i = x1; i <= x2; i++) for(int j = y1; j <= y2; j++) vis[i][j] = 0;
		int ans = 0;
		for(int i = x1; i <= x2; i++) for(int j = y1; j <= y2; j++) if(/**/s[i][j] == '1' && !vis[i][j]) vis[i][j] = 1, dfs(i, j), ans++;
		writeln(ans);
	}
	return Case ^= Case ^ Case;
}
void initial_function(int argc, char **argv) {
	**argv = argc; /* <- place_holder
	you won't give up no matter what happens, will you?
	code time: 00:
	---

[11:55:46] [编译警告] [
C:/Users/y_kx_/AppData/Local/Temp/CP Editor-IeVYLY/sol.cpp: In function 'bool major(int)':
C:/Users/y_kx_/AppData/Local/Temp/CP Editor-IeVYLY/sol.cpp:59:25: warning: unused variable 'm' [-Wunused-variable]
   59 |         int n = read(), m = read(), q = read();
      |                         ^
]

	*/
	freopen("unicom.in", "r", stdin);
	freopen("unicom.out", "w", stdout);
}
signed main(int argc, char **argv) {
	initial_function(argc, argv);
	int Case = 1, Maxcase = 1;
	for (
#ifdef multiple_testcase
		  Maxcase = read()
#endif
				     	  ;
#ifndef infinite_testcase
							Case <= Maxcase
#endif
				     					   ; Case++)
#ifdef output_Yes_No
		puts(major(Case) ? Y_E_S : N__O);
#else
		major(Case);
#endif
	return DUST ^ 0x147;
}
